package com.example.demo.huawei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * 英文输入法
 */
public class OD45 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String pre = sc.nextLine();

        //System.out.println(str);
        //System.out.println(pre);
        StringBuilder sb = new StringBuilder();
        for (char c : str.toCharArray()) {
            if (Character.isWhitespace(c) || Character.isLetter(c)) {
                sb.append(c);
            }
            if (c == '\'') {
                sb.append(" ");
            }
        }
        String[] split = sb.toString().split("\\s");
        List<String> words = new ArrayList<>();

        for (String s : split) {
            if (s.startsWith(pre)) {
                words.add(s);
            }
        }
        Collections.sort(words);
        sb = new StringBuilder();
        for (String s : words) {
            sb.append(s).append(" ");
        }
        if (!words.isEmpty()) {
            System.out.println(sb.deleteCharAt(sb.length() - 1));
        } else {
            System.out.println(pre);
        }
    }
}
